import time

from selenium.webdriver.common.by import By
from common.Utils import ForumDriver

class ForumRegister:
    driver = ""
    url = ""

    def __init__(self):
        self.driver = ForumDriver.driver
        self.url = "http://127.0.0.1:9580/sign-up.html"
        self.driver.get(self.url)

    def ForumRegisSucTest(self):
        #检查一下页面元素
        sign = self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > h2").text
        print("注册页面标识："+sign)
        #检查一下勾选服务条例框
        self.driver.find_element(By.CSS_SELECTOR,"#policy")
        #检查一下注册按钮存在
        self.driver.find_element(By.CSS_SELECTOR, "#submit")

        #在用户名输入框输入用户名
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("wwt")
        #在昵称输入框输入昵称
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").send_keys("花开富贵")
        #在密码输入框，输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("17888")
        #在确认密码输入框，输入密码
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").send_keys("17888")
        #勾选同意服务条例
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        ForumDriver.GetScreeShot()
        #点击注册按钮
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        time.sleep(2)
        JumpTitle = self.driver.title
        JumpUrl = self.driver.current_url
        print(JumpTitle)
        print(JumpUrl)
        assert JumpTitle == "比特论坛 - 用户注册"
        assert JumpUrl== "http://127.0.0.1:9580/sign-in.html"

        ForumDriver.GetScreeShot()

    def ForumRegisFailTest(self):
        # #不输入用户名测试注册
        # # 检查一下页面元素
        # sign = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > h2").text
        # print("注册页面标识：" + sign)
        # # 检查一下勾选服务条例框
        # self.driver.find_element(By.CSS_SELECTOR, "#policy")
        # # 检查一下注册按钮存在
        # self.driver.find_element(By.CSS_SELECTOR, "#submit")
        # # 在用户名输入框不输入用户名
        # self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("")
        # # 在昵称输入框输入昵称
        # self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("花开富贵")
        # # 在密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("2025327")
        # # 在确认密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("2025327")
        # # 勾选同意服务条例
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # # 点击注册按钮
        # self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # ForumDriver.GetScreeShot()
        # time.sleep(2)

        # # 不输入昵称测试注册
        # # 检查一下页面元素
        # sign = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > h2").text
        # print("注册页面标识：" + sign)
        # # 检查一下勾选服务条例框
        # self.driver.find_element(By.CSS_SELECTOR, "#policy")
        # # 检查一下注册按钮存在
        # self.driver.find_element(By.CSS_SELECTOR, "#submit")
        # # 在用户名输入框不输入用户名
        # self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("wwt")
        # # 在昵称输入框输入昵称
        # self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("")
        # # 在密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("2025327")
        # # 在确认密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("2025327")
        # # 勾选同意服务条例
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # # 点击注册按钮
        # self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # ForumDriver.GetScreeShot()
        # time.sleep(2)

        # # 不输入密码测试注册
        # # 检查一下页面元素
        # sign = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > h2").text
        # print("注册页面标识：" + sign)
        # # 检查一下勾选服务条例框
        # self.driver.find_element(By.CSS_SELECTOR, "#policy")
        # # 检查一下注册按钮存在
        # self.driver.find_element(By.CSS_SELECTOR, "#submit")
        # # 在用户名输入框不输入用户名
        # self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("wwt")
        # # 在昵称输入框输入昵称
        # self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("花开富贵")
        # # 在密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("")
        # # 在确认密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("2025327")
        # # 勾选同意服务条例
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # # 点击注册按钮
        # self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # ForumDriver.GetScreeShot()
        # time.sleep(2)

        # # 不输入确认密码测试注册
        # # 检查一下页面元素
        # sign = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > h2").text
        # print("注册页面标识：" + sign)
        # # 检查一下勾选服务条例框
        # self.driver.find_element(By.CSS_SELECTOR, "#policy")
        # # 检查一下注册按钮存在
        # self.driver.find_element(By.CSS_SELECTOR, "#submit")
        # # 在用户名输入框不输入用户名
        # self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("wwt")
        # # 在昵称输入框输入昵称
        # self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("花开富贵")
        # # 在密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("2025327")
        # # 在确认密码输入框，输入密码
        # self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("")
        # # 勾选同意服务条例
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # # 点击注册按钮
        # self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # ForumDriver.GetScreeShot()
        # time.sleep(2)

        # 不勾选服务条例测试注册
        # 检查一下页面元素
        sign = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > h2").text
        print("注册页面标识：" + sign)
        # 检查一下勾选服务条例框
        self.driver.find_element(By.CSS_SELECTOR, "#policy")
        # 检查一下注册按钮存在
        self.driver.find_element(By.CSS_SELECTOR, "#submit")
        # 在用户名输入框不输入用户名
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("wwt")
        # 在昵称输入框输入昵称
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("花开富贵")
        # 在密码输入框，输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("2025327")
        # 在确认密码输入框，输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("2025327")
        # 不勾选同意服务条例
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # 点击注册按钮
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        ForumDriver.GetScreeShot()
        time.sleep(2)










